<template>
	<view class="content">
		<view class="top">
			<view class="index-button">
				<view class="icon iconfont icon-1804-liufupinggongnengtubiao_huaban1fuben23"></view>
			</view>
			<view class="top-bar">	
				<view class="nav-item" 
				:class="{'actived':currentType==typeItem.id}"
				v-for="(typeItem,index) in typeList" 
				@click="typeClick(typeItem)">
				{{typeItem.contentTypeName}}
				</view>
			</view>
			<!-- <view class="index-button">
				<view class="icon iconfont icon-icon_search"></view>
			</view> -->
		</view>
		<view class="images-wall">
			<view class="flow wall-left">
				<view class="image-item" v-for="(contentInfo,index) in contentList" v-if="index%2==0">
					<image :src="imageServer+contentInfo.contentImg" mode="widthFix" class="image" @click="contentClick(contentInfo)"></image>
					<view class="title">{{contentInfo.contentText}}</view>
					<view class="author-bar">
						<view class="author-info">
							<view class="avartar">
								<image :src="contentInfo.account.head"></image>
							</view>
							<view class="author">{{contentInfo.contentAuthor}}</view>
						</view>
						<view class="praise-count">
							<view class="icon iconfont icon-shoucang1"></view>
							<view class="number">{{contentInfo.contentPraiseCount>10000?(contentInfo.contentPraiseCount/10000).toFixed(2)+"万":contentInfo.contentPraiseCount}}</view>
						</view>
					</view>
				</view>
			</view>
			<view class="flow wall-right">
				<view class="image-item" v-for="(contentInfo,index) in contentList" v-if="index%2>0">
					<image :src="imageServer+contentInfo.contentImg" mode="widthFix" class="image" @click="contentClick(contentInfo)"></image>
					<view class="title">{{contentInfo.contentText}}</view>
					<view class="author-bar">
						<view class="author-info">
							<view class="avartar">
								<image :src="contentInfo.account.head"></image>
							</view>
							<view class="author">{{contentInfo.contentAuthor}}</view>
						</view>
						<view class="praise-count">
							<view class="icon iconfont icon-shoucang1"></view>
							<view class="number">{{contentInfo.contentPraiseCount>10000?(contentInfo.contentPraiseCount/10000).toFixed(2)+"万":contentInfo.contentPraiseCount}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view>
			<image src="../../static/publish.png" @click="gotoPublish()" style="width: 100rpx;height:100rpx;position: fixed;bottom:85rpx;right:55rpx;"></image>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//分类数据数组
				typeList:[],
				//记录被激活的分类
				currentType:0,
				contentList:[],
				imageServer:""
			}
		},
		onLoad() {
			this.imageServer=this.serverUrl;
			//页面加载时调用获取分类数据的方法
			this.loadTypeData();
			
		},
		onPullDownRefresh(){
				this.loadTypeData();
		},
		methods: {
			gotoPublish(){
				uni.navigateTo({
					url:"../releaseDaily/releaseDaily"
				})
			},
			typeClick(typeItem){
				//记录被点击的分类
				this.currentType=typeItem.id;
				console.log("被点击的分类",typeItem,"currentType值为",this.currentType);
				this.loadContentData();
			},
			//获取分类数据
			
			loadTypeData(){
				//发送请求
				uni.request({
					url:this.serverUrl+"/api/content-types",
					method:"GET",
					success:(result)=>{
						console.log("获取分类数据回调",result);
						if(result.statusCode==200){
							//将获取到的数据赋值给分类数组
							this.typeList=result.data;
							//分类数据加载完成后，默认指定第一个元素为激活状态
							if(this.typeList.length>0){
								this.currentType=this.typeList[0].id
								this.loadContentData();
							}
						}
					}
				})
			},
			//获取内容数据
			loadContentData(){
				uni.showLoading({
					title:'加载中'
				})
				uni.request({
					url:this.serverUrl+"/api/content-infos/type?typeId="+this.currentType+"&page=0&size=10",
					method:'GET',
					success:(result)=>{
						console.log("获取到内容数据",result);
						if(result.statusCode==200){
							this.contentList=result.data.content;
						}else{
							uni.showToast({
								title:"获取内容数据失败",
								icon:"none"
							})
						}
						uni.hideLoading();
						uni.stopPullDownRefresh();
					}
				});
			},
			contentClick(contentInfo){
				uni.navigateTo({
					url:'../contentinfo/contentinfo?id='+contentInfo.id
				})
			}
		}
	}
</script>

<style>
	.content {
		padding-top:80px;
		padding-bottom:50px;
		background-color: #efefef;
	}
	.top{
		width:750rpx;
		position:fixed;
		display: flex;
		justify-content: center;
		align-items: center;
		top:0;
		left:0;
		z-index: 999;
		background-color: #fff;
	}
	.top-bar{
		flex:1;
		overflow-x: scroll;
		display: flex;
		flex-wrap: nowrap;
		padding:20rpx 10rpx;
		align-items: center;
		justify-content: start;
		position:relative;
	}
	.index-button{
		flex-shrink: 0;
		width:80rpx;
	}
	.index-button .icon{
		font-size:46px;
		color:#fce71c;
	}
	.index-button .icon-icon_search{
		color:#7A7E83;
		font-size:30px;
	}
	.top-bar .nav-item{
		margin-right:50rpx;
		flex-shrink: 0;
		font-size:100%;
		color:#a2a2a2;
		padding:15rpx 5rpx;
	}
	.top-bar .nav-item.actived{
		color:#000000;
		font-size:105%;
		text-shadow: 0px 0px 1px rgba(0,0,0,0.3);
		border-bottom:2px solid #efefef;
	}
	.images-wall{
		display: flex;
		width:750rpx;
		justify-content: space-between;
		align-items: flex-start;
		background:#ebebeb;
		min-height:100vh;
		flex-wrap: wrap;
	}
	.images-wall .image-item{
		width:363rpx;
		flex-shrink: 0;
		border-radius: 5px;
		display: flex;
		flex-direction: column;
		justify-content: center;
		background:#fff;
		margin-top:20rpx;
		margin-left:7rpx;
		margin-right:7rpx;
	}
	.images-wall .image-item .image{
		width:100%;
		min-height:60px;
		border-radius:5px 5px 0 0;
	}
	.images-wall .image-item .title{
		padding:5rpx 10rpx;
	}
	.images-wall .image-item .author-bar{
		padding:5rpx 10rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
	.images-wall .image-item .author-bar .author{
		color:#686868;
		font-size:70%;
		margin-left:20rpx;
	}
	.images-wall .image-item .author-bar .author-info{
		display: flex;
		justify-content: flex-start;
		align-items: center;
	}
	.images-wall .image-item .author-bar .author-info .avartar{
		width:50rpx;
		height:50rpx;
	}
	.images-wall .image-item .author-bar .author-info .avartar image{
		width:100%;
		height:100%;
		border-radius: 50%;
	}
	.images-wall .image-item .author-bar .praise-count{
		display: flex;
		align-items: center;
		color:#686868;
	}
	.images-wall .image-item .author-bar .praise-count .number{
		margin-left:10rpx;
		font-size:90%;
	}
	
</style>
